Socket
Socket
Sign inDemoInstall

@csstools/css-color-parser

Package Overview
Dependencies
4
Maintainers
3
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@csstools/css-color-parser


Version published
Maintainers
3
Created

Package description

What is @csstools/css-color-parser?

@csstools/css-color-parser is an npm package designed to parse CSS color values. It can handle a variety of color formats including named colors, hex codes, RGB, RGBA, HSL, and HSLA. This package is useful for developers who need to manipulate or validate CSS color values in their JavaScript applications.

What are @csstools/css-color-parser's main functionalities?

Parse Named Colors

This feature allows you to parse named CSS colors. The code sample demonstrates how to parse the named color 'red' and log the resulting color object.

const { parse } = require('@csstools/css-color-parser');
const color = parse('red');
console.log(color);

Parse Hex Colors

This feature allows you to parse hex color codes. The code sample demonstrates how to parse the hex color '#ff0000' and log the resulting color object.

const { parse } = require('@csstools/css-color-parser');
const color = parse('#ff0000');
console.log(color);

Parse RGB Colors

This feature allows you to parse RGB color values. The code sample demonstrates how to parse the RGB color 'rgb(255, 0, 0)' and log the resulting color object.

const { parse } = require('@csstools/css-color-parser');
const color = parse('rgb(255, 0, 0)');
console.log(color);

Parse RGBA Colors

This feature allows you to parse RGBA color values. The code sample demonstrates how to parse the RGBA color 'rgba(255, 0, 0, 0.5)' and log the resulting color object.

const { parse } = require('@csstools/css-color-parser');
const color = parse('rgba(255, 0, 0, 0.5)');
console.log(color);

Parse HSL Colors

This feature allows you to parse HSL color values. The code sample demonstrates how to parse the HSL color 'hsl(0, 100%, 50%)' and log the resulting color object.

const { parse } = require('@csstools/css-color-parser');
const color = parse('hsl(0, 100%, 50%)');
console.log(color);

Parse HSLA Colors

This feature allows you to parse HSLA color values. The code sample demonstrates how to parse the HSLA color 'hsla(0, 100%, 50%, 0.5)' and log the resulting color object.

const { parse } = require('@csstools/css-color-parser');
const color = parse('hsla(0, 100%, 50%, 0.5)');
console.log(color);

Other packages similar to @csstools/css-color-parser

Readme

Source

CSS Color Parser

npm version Build Status Discord

Usage

Add CSS Color Parser to your project:

npm install @csstools/css-color-parser @csstools/css-parser-algorithms @csstools/css-tokenizer --save-dev
import { color } from '@csstools/css-color-parser';
import { isFunctionNode, parseComponentValue } from '@csstools/css-parser-algorithms';
import { serializeRGB } from '@csstools/css-color-parser';
import { tokenize } from '@csstools/css-tokenizer';

// color() expects a parsed component value.
const hwbComponentValue = parseComponentValue(tokenize({ css: 'hwb(10deg 10% 20%)' }));
const colorData = color(hwbComponentValue);
if (colorData) {
	console.log(colorData);

	// serializeRGB() returns a component value.
	const rgbComponentValue = serializeRGB(colorData);
	console.log(rgbComponentValue.toString());
}

Keywords

FAQs

Last updated on 06 Jul 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc